// mysql/User.js
const Sequelize = require("sequelize");
const sequelize = require("./index"); // 确保路径正确

const { DataTypes } = Sequelize;

const User = sequelize.define(
  "User",
  {
    // 用户ID
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: "用户ID",
    },
    // 用户名
    username: {
      type: DataTypes.STRING(50),
      allowNull: true,
      unique: true,
      comment: "用户名",
    },
    // 密码
    password: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: "密码",
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      field: "created_at",
      comment: "记录创建时间",
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
      onUpdate: Sequelize.literal("CURRENT_TIMESTAMP"),
      field: "updated_at",
      comment: "记录更新时间",
    },
  },
  {
    tableName: "users",
    timestamps: true,
  }
);

module.exports = User;
